from flask import Blueprint,request,jsonify
import json
from db import db1

bp_cate = Blueprint('cate',__name__)


@bp_cate.route('/cate',methods=['POST','GET'])
def cate():
    if request.method== 'POST':
        data = request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
        
        res = """insert into cate(name) values('%s')"""%(data['name'])
        db1.insert(res)
        return jsonify({"code":200})
    elif request.method == 'GET':
        sql = 'select * from cate'
        list = db1.findall(sql)
        return jsonify({'code':200,'list':list})

